home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Night of the Living Disc / Night of the Living Disc.hdv / Dev.CD.5 / Tools / File.Type.Notes / FTN.E0.0001 < prev    next >
Encoding:
Text File  |  1990-03-03  |  15.9 KB  |  303 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. File Type Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. File Type:         $E0 (224)
  7. Auxiliary Type:    $0001
  8.  
  9. Full Name:     AppleSingle File
  10. Short Name:    AppleSingle File
  11.  
  12. Revised by:    Matt Deatherage                                     March 1990
  13. Written by:    Matt Deatherage                                     March 1989
  14.  
  15. Files of this type and auxiliary type contain a file in AppleSingle format.
  16. Changes since March 1989:  Clarified the Real Name entry field.
  17. _____________________________________________________________________________
  18.  
  19. AppleSingle is one of two standards (the other is AppleDouble) put forth by 
  20. Apple Computer, Inc. for representing files on foreign file systems while 
  21. preserving all attributes of the file's home system on file systems that do 
  22. not support the same attributes.
  23.  
  24. Experience indicated that a single format would be inadequate to cover all 
  25. cases.  Two closely related formats, however, can serve most needs.  Although 
  26. the primary impetus for developing these formats is storing extended files 
  27. (files with both resource and data forks) on file systems that do not support 
  28. the notion of two forks, the proposed formats are general enough that they can 
  29. be used to represent a file from any file system on any other file system.
  30.  
  31. AppleSingle keeps all attributes and the contents of both forks in a single 
  32. file in the foreign file system, and this Note describes this file format.  
  33. AppleDouble keeps the data fork as a separate file from the file attributes 
  34. and the resource fork, and is described in the File Type Notes for File Type 
  35. $E0, Auxiliary Types $0002 and $0003.
  36.  
  37. AppleSingle is intended to be used primarily as a storage format, especially 
  38. for cases where you must store an extended file on a foreign file system and 
  39. later reconstruct the extended file.  AppleDouble is more appropriate for 
  40. applications where the users of the foreign file system might want to modify 
  41. the contents of the file.  Since most applications keep file data in the data 
  42. fork, AppleDouble format saves the contents of the data fork in one file.  All 
  43. other file attributes, including the resource fork, are kept in a separate 
  44. file.
  45.  
  46.  
  47. Reasons for Using AppleSingle
  48.  
  49. There are several reasons for supporting an interchange format between file 
  50. systems.  Perhaps the most germane is one of the least obvious:  handling 
  51. extended files on foreign file systems which do not support extended files.
  52.  
  53. For example, the ProDOS FST in GS/OS can create an extended file on a ProDOS 
  54. disk.  However, ProDOS 8 is unable to operate on the file, since it sees it as 
  55. having an unsupported storage type.  If a telecommunications program or other 
  56. utility capable of transferring files is operating under ProDOS 8 and attempts 
  57. to receive an extended file, it is unable to create the file.
  58.  
  59. At this point, the application could use READ_BLOCK and WRITE_BLOCK commands, 
  60. along with a knowledge of the ProDOS file system, to create the file on its 
  61. own.  However, this is strongly discouraged.  The ProDOS file system format 
  62. for extended files is not documented and could change in the future.  In 
  63. addition, the program could be running on a eight-bit system.  If the disk is 
  64. only used on an eight-bit system, the extended files would not only be 
  65. unwanted, but also unremovable without using the disk on an Apple IIGS or 
  66. later system running GS/OS.
  67.  
  68. However, if the application is aware of the AppleSingle format, it can quickly 
  69. store an extended file in AppleSingle, leaving the conversion back to the 
  70. extended file to GS/OS, or another operating system.  This is the recommended 
  71. way for ProDOS 8 applications to create and handle extended files.  Use either 
  72. AppleSingle or AppleDouble.
  73.  
  74.  
  75. AppleSingle Format
  76.  
  77. An AppleSingle file contains a header followed by data.  The header consists 
  78. of several fixed fields and a list of entry descriptors, each pointing to an 
  79. entry.  Apple defines the following standard entries:  Data Fork, Resource 
  80. Fork, Real Name (name in the home file system), Comment, Icon and File Info.  
  81. Each entry is optional, so it may not appear in the file.
  82.  
  83. Note:  All numeric entries, including entries representing ProDOS data 
  84.        structures (such as file type and auxiliary type) are Reverse 
  85.        ordered.  This is provided so any host CPU can attempt to 
  86.        interpret entries in the header without having to know the 
  87.        standard byte-ordering of the home file system.  Therefore, in 
  88.        this Note you see descriptive entries like "Rev. 4 Bytes."  This 
  89.        serves as a reminder that all header fields are stored high byte 
  90.        first, even though the notation Bytes does not imply any specific 
  91.        ordering in other File Type Notes.
  92.  
  93. Also note that ASCII strings are not stored in reverse order, just non-ASCII 
  94. constants.
  95.  
  96. The Header:
  97.  
  98. Magic Number         Rev. Long    The Magic Number field is modeled after 
  99.                                   the feature in UNIX.  It is intended to be 
  100.                                   used in whatever way the foreign file 
  101.                                   system distinguishes a file as AppleSingle 
  102.                                   format.  See the section "Identifying 
  103.                                   AppleSingle Files."  The Magic Number for 
  104.                                   AppleSingle format is $00051600, which is 
  105.                                   stored reverse as $00 $05 $16 $00 (reverse 
  106.                                   of normal 65816/6502 order).
  107. Version Number       Rev. Long    The version of AppleSingle format, in case 
  108.                                   the format evolves (more fields may be 
  109.                                   added to the header).  The version 
  110.                                   described here is $00010000, stored 
  111.                                   (reverse) as $00 $01 $00 $00.
  112. Home File System     16 Bytes     A fixed-length, 16-byte ASCII string not 
  113.                                   preceded by a length byte, but possibly 
  114.                                   padded with blanks.  Apple has defined 
  115.                                   these values:
  116.                                   "ProDOS"    $50726F444F5320202020202020202020
  117.                                   "Macintosh" $4D6163696E746F736820202020202020
  118.                                   "MS-DOS"    $4D532D444F5320202020202020202020
  119.                                   "Unix"      $556E9878202020202020202020202020
  120.                                   "VAX VMS"   $56415820564D53202020202020202020
  121.                                   Apple welcomes suggestions for other file 
  122.                                   systems that should be included in this 
  123.                                   list.
  124. Number of entries    Rev. Word    Tells how many different entries are 
  125.                                   included in the file.  This unsigned 
  126.                                   reverse word may be zero.  If it is non-
  127.                                   zero, then that number of entry 
  128.                                   descriptors immediately follows this 
  129.                                   field.
  130.  
  131.  
  132. For Each Entry:
  133.  
  134. Entry ID             Rev. Long    Identifies the entry.  Apple has defined 
  135.                                   the following Entry IDs and their values:
  136.                                   1 = Data Fork
  137.                                   2 = Resource Fork
  138.                                   3 = Real Name (The file's name in the home 
  139.                                       file system)
  140.                                   4 = Comment* (standard Macintosh comment)
  141.                                   5 = Icon, B&W* (standard Macintosh black 
  142.                                       and white icon)
  143.                                   6 = Icon, Color* (reserved for Macintosh 
  144.                                       color icon)
  145.                                   7 = File Info (file attributes, dates, etc.)
  146.                                   9 = Finder Info* (standard Macintosh 
  147.                                       Finder Info)
  148.                                   Entry IDs marked with asterisks (*) are 
  149.                                   not used for most files created under 
  150.                                   ProDOS or GS/OS.  Furthermore, icon 
  151.                                   entries probably do not appear in most 
  152.                                   files since they are typically stored as a 
  153.                                   bundle in the application file's resource 
  154.                                   fork on the Macintosh.  Apple reserves the 
  155.                                   range of Entry IDs from $0 to $7FFFFFFF 
  156.                                   for future use.  The rest of the range is 
  157.                                   available for other systems to define 
  158.                                   their own entries.  Apple does not 
  159.                                   arbitrate the use of the rest of the 
  160.                                   range.
  161.                                   Descriptions of the standard entries are 
  162.                                   given below.
  163. Offset               Rev. Long    An unsigned reverse long which indicates 
  164.                                   the byte offset from the start of the file 
  165.                                   to the start of the entry.
  166. Entry Length         Rev. Long    An unsigned reverse long which indicates 
  167.                                   the length of the entry in bytes.  The 
  168.                                   length may be zero.
  169.  
  170.  
  171. Standard Entries:
  172.  
  173. The Real Name Entry:
  174.  
  175. The Real Name entry indicates the file's original filename in the host file 
  176. system.  This is not a Pascal or C string; it is just ASCII data.  The length 
  177. is indicated by the Entry Length field for the Real Name entry.
  178.  
  179. The File Info Entry:
  180.  
  181. The File Info entry (Entry ID = 7) is different for each home file system.  
  182. For ProDOS files, the entry is 16 bytes long and consists of the creation date 
  183. and time and the modification date and time in ProDOS 8 (ProDOS 16/class zero 
  184. GS/OS) form, the access word, a two-byte file type and four-byte auxiliary 
  185. type.  This is detailed in standard format below, along with defined File Info 
  186. entries for some other file systems.
  187.  
  188. ProDOS:
  189.  
  190. Create Date        Rev. 2 Bytes  Creation date packed into standard 
  191.                                  ProDOS 8 format.
  192. Create Time        Rev. 2 Bytes  Creation time packed into standard 
  193.                                  ProDOS 8 format.
  194. Modification Date  Rev. 2 Bytes  Modification date packed into 
  195.                                  standard ProDOS 8 format.
  196. Modification Time  Rev. 2 Bytes  Modification time packed into 
  197.                                  standard ProDOS 8 format.
  198. Access             Rev. Word     The file's access.  This may be used 
  199.                                  directly in ProDOS 16 or GS/OS calls; only 
  200.                                  the low byte is significant to ProDOS 8.
  201. File Type          Rev. Word     The file type of the original file.  Only 
  202.                                  the low byte is significant to ProDOS 8.
  203. Auxiliary Type     Rev. Long     The auxiliary type of the original file.  
  204.                                  Only the low word is significant to ProDOS 8.
  205.  
  206. Note:  Although the ProDOS Access field, File Type and Auxiliary Type are 
  207.        the same length as found in ProDOS 16 and GS/OS structures, the 
  208.        Create and Modification Dates and Times are stored in two-byte 
  209.        (albeit byte-reversed) ProDOS 8 format, not eight-byte Apple IIGS 
  210.        format.
  211.  
  212. Macintosh:
  213.  
  214. Create Date          Rev. Long    Unsigned number of seconds between 
  215.                                   January 1, 1904, and the creation time of 
  216.                                   this file.
  217. Modification Date    Rev. Long    Unsigned number of seconds between 
  218.                                   January 1, 1904, and the last modification 
  219.                                   of this file.
  220. Last Backup Date     Rev. Long    Unsigned number of seconds between 
  221.                                   January 1, 1904, and the last backup time 
  222.                                   of this file.
  223. Attributes           Rev. Long    32 boolean flags.  Once the bytes are 
  224.                                   unreversed, bit zero is the locked bit and 
  225.                                   bit one is the protected bit.
  226.  
  227. MS-DOS:
  228.  
  229. Modification Date    Rev. 4 Bytes    MS-DOS format modification date.
  230. Attributes           Rev. 2 Bytes    MS-DOS attributes.
  231.  
  232. Unix:
  233.  
  234. Create Date/Time       Rev. 4 Bytes    Unix creation date and time.
  235. Last Use Date/Time     Rev. 4 Bytes    Unix time for the last 
  236.                                        time this file was used.
  237. Last Mod. Date/Time    Rev. 4 Bytes    Unix time for the last 
  238.                                        time this file was modified.
  239.  
  240.  
  241. The Finder Info Entry:
  242.  
  243. The Finder Info entry (Entry ID = 9) is for files where the host file system 
  244. is Macintosh.  It consists of 16 bytes of Finder Info followed by 16 bytes of 
  245. Extended Finder Info.  These are the fields ioFlFndrInfo followed by 
  246. ioFlXFndrInfo, as described in Inside Macintosh, Volume IV-183.  Newly created 
  247. files have zeroes in all Finder Info subfields.  If you are creating an 
  248. AppleSingle file whose home system is Macintosh, you may zero all unknown 
  249. fields, but you may want to set the fdType and fdCreator subfields.
  250.  
  251.  
  252. The Entries:
  253.  
  254. The entries themselves follow the header field and the entry descriptors.  The 
  255. actual data representing each entry must be in a single, contiguous block.  
  256. The offset field in that entry's descriptor points to it.  The entries could 
  257. appear in any order, but since the data fork is the entry that is most 
  258. commonly extended, Apple strongly recommends that the data fork always be kept 
  259. last in the file to facilitate its extension.  Apple also recommends that 
  260. those entries that are most often read, such as Real Name, File Info (and 
  261. Finder Info if present) be kept as close as possible to the header to maximize 
  262. the probability that a read of the first few blocks of the file retrieves 
  263. these entries.
  264.  
  265. It is possible to have holes in the file (unused space between entries).  To 
  266. find the holes, you must take the list of entry descriptors and sort them into 
  267. increasing offset order.  If the offset field of an entry is greater than the 
  268. offset plus the length of the previous entry (sorted), then a hole exists 
  269. between the entries.  You can make use of such holes; for example, if a file's 
  270. comment is ten bytes long, you could create a hole of 190 bytes after the 
  271. comment field to easily allow for the comment to later expand to its maximum 
  272. length of 200 bytes.  Because an AppleSingle file may contain holes, you must 
  273. find each entry by getting its offset from its entry descriptor, not by 
  274. assuming that it begins after the previous entry.
  275.  
  276. Byte ordering in file header fields follows 68000 convention, and each header 
  277. field has been so noted by the Reverse operator.
  278.  
  279.  
  280. Identifying AppleSingle files
  281.  
  282. As this is an interchange format, from a ProDOS directory entry there is no 
  283. way to guarantee which files are AppleSingle files.  Apple has allocated File 
  284. Type $E0, Auxiliary Type $0001 for files which are AppleSingle files.  We 
  285. strongly encourage ProDOS 8 and GS/OS applications to use this file type and 
  286. auxiliary type assignment when creating AppleSingle files.
  287.  
  288. AppleSingle files which do not have file type $E0 and auxiliary type $0001 can 
  289. most easily be identified by opening them and attempting to interpret them.  
  290. If they are not AppleSingle files, the Magic Number is not contained in the 
  291. first four bytes of the file.  The chances that the file would begin with 
  292. those four bytes and not be an AppleSingle file, on a purely random basis, are 
  293. 4,294,967,295 to 1.  The chances that both the Magic Number and the Version 
  294. bytes would be the same in a non-AppleSingle file are roughly 1.8 x 10^19 
  295. to 1.
  296.  
  297. Further Reference
  298. _____________________________________________________________________________
  299.   o  Inside Macintosh, Volume IV
  300.   o  ProDOS 8 Technical Reference Manual
  301.   o  GS/OS Reference, Volume I
  302.  
  303.